<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb5">
      <el-col :span="1.5">
        <el-button
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:infor:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:infor:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:infor:remove']"
        >删除</el-button>
      </el-col>
      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px" class="el-form-search">
                        <el-form-item label="标题" prop="title" class="el-form-search-item">
                            <el-input
                                    v-model="queryParams.title"
                                    placeholder="请输入标题"
                                    clearable
                                    size="mini"
                                    @keyup.enter.native="handleQuery"
                            />
                        </el-form-item>
                        <el-form-item label="创建人" prop="createor" class="el-form-search-item">
                            <el-input
                                    v-model="queryParams.createor"
                                    placeholder="请输入创建人"
                                    clearable
                                    size="mini"
                                    @keyup.enter.native="handleQuery"
                            />
                        </el-form-item>
                        <el-form-item label="创建时间" prop="createTime" class="el-form-search-item">
                            <el-date-picker clearable size="mini"
                                            v-model="queryParams.createTime"
                                            type="date"
                                            value-format="yyyy-MM-dd"
                                            placeholder="选择创建时间">
                            </el-date-picker>
                        </el-form-item>
                        <el-form-item label="文章作者" prop="author" class="el-form-search-item">
                            <el-input
                                    v-model="queryParams.author"
                                    placeholder="请输入文章作者"
                                    clearable
                                    size="mini"
                                    @keyup.enter.native="handleQuery"
                            />
                        </el-form-item>
                        <el-form-item label="扩展字段1" prop="extend1" class="el-form-search-item">
                            <el-input
                                    v-model="queryParams.extend1"
                                    placeholder="请输入扩展字段1"
                                    clearable
                                    size="mini"
                                    @keyup.enter.native="handleQuery"
                            />
                        </el-form-item>
                        <el-form-item label="扩展字段2" prop="extend2" class="el-form-search-item">
                            <el-date-picker clearable size="mini"
                                            v-model="queryParams.extend2"
                                            type="date"
                                            value-format="yyyy-MM-dd"
                                            placeholder="选择扩展字段2">
                            </el-date-picker>
                        </el-form-item>
                        <el-form-item label="扩展字段3" prop="extend3" class="el-form-search-item">
                            <el-date-picker clearable size="mini"
                                            v-model="queryParams.extend3"
                                            type="date"
                                            value-format="yyyy-MM-dd"
                                            placeholder="选择扩展字段3">
                            </el-date-picker>
                        </el-form-item>
                        <el-form-item label="启用扩展字段6存放列表名称" prop="extend6" class="el-form-search-item">
                            <el-input
                                    v-model="queryParams.extend6"
                                    placeholder="请输入启用扩展字段6存放列表名称"
                                    clearable
                                    size="mini"
                                    @keyup.enter.native="handleQuery"
                            />
                        </el-form-item>
                        <el-form-item label="扩展字段7" prop="extend7" class="el-form-search-item">
                            <el-input
                                    v-model="queryParams.extend7"
                                    placeholder="请输入扩展字段7"
                                    clearable
                                    size="mini"
                                    @keyup.enter.native="handleQuery"
                            />
                        </el-form-item>
                        <el-form-item label="扩展字段8" prop="extend8" class="el-form-search-item">
                            <el-input
                                    v-model="queryParams.extend8"
                                    placeholder="请输入扩展字段8"
                                    clearable
                                    size="mini"
                                    @keyup.enter.native="handleQuery"
                            />
                        </el-form-item>
            <el-form-item class="el-form-search-item">
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
    </el-row>

    <el-table ref="list" :height="tableHeight" v-loading="loading" :data="inforList" @selection-change="handleSelectionChange" @row-click="handleRowClick" highlight-current-row>
      <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="#" type="index" width="50" align="center">
            <template scope="scope">
          <span>{{
            (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1
          }}</span>
            </template>
        </el-table-column>
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="标题" align="center" prop="title" />
      <el-table-column label="0：政策解读 1：党史百年 2：特色党建 3：三会一课 4：乡村振兴 5： 司机之家" align="center" prop="type" />
      <el-table-column label="内容" align="center" prop="content" />
      <el-table-column label="创建人" align="center" prop="createor" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="文章作者" align="center" prop="author" />
      <el-table-column label="扩展字段1" align="center" prop="extend1" />
      <el-table-column label="扩展字段2" align="center" prop="extend2" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.extend2, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="扩展字段3" align="center" prop="extend3" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.extend3, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="扩展字段4" align="center" prop="extend4" />
      <el-table-column label="扩展字段4" align="center" prop="extend5" />
      <el-table-column label="启用扩展字段6存放列表名称" align="center" prop="extend6" />
      <el-table-column label="扩展字段7" align="center" prop="extend7" />
      <el-table-column label="扩展字段8" align="center" prop="extend8" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:infor:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:infor:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body :close-on-click-modal="false" v-dialogDrag>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="标题" prop="title">
          <el-input v-model="form.title" placeholder="请输入标题" />
        </el-form-item>
        <el-form-item label="内容">
          <editor v-model="form.content" :min-height="192"/>
        </el-form-item>
        <el-form-item label="创建人" prop="createor">
          <el-input v-model="form.createor" placeholder="请输入创建人" />
        </el-form-item>
        <el-form-item label="文章作者" prop="author">
          <el-input v-model="form.author" placeholder="请输入文章作者" />
        </el-form-item>
        <el-form-item label="扩展字段123213" prop="extend1">
          <el-input v-model="form.extend1" placeholder="请输入扩展字段1" />
        </el-form-item>
        <el-form-item label="扩展字段2" prop="extend2">
          <el-date-picker clearable size="mini"
            v-model="form.extend2"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择扩展字段2">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="扩展字段3" prop="extend3">
          <el-date-picker clearable size="mini"
            v-model="form.extend3"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择扩展字段3">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="启用扩展字段6存放列表名称" prop="extend6">
          <el-input v-model="form.extend6" placeholder="请输入启用扩展字段6存放列表名称" />
        </el-form-item>
        <el-form-item label="扩展字段7" prop="extend7">
          <el-input v-model="form.extend7" placeholder="请输入扩展字段7" />
        </el-form-item>
        <el-form-item label="扩展字段8" prop="extend8">
          <el-input v-model="form.extend8" placeholder="请输入扩展字段8" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInfor, getInfor, delInfor, addInfor, updateInfor } from "@/api/partyBuilding/article";

export default {
  name: "Infor",
  data() {
    return {
      // 表格高度
      tableHeight: document.documentElement.clientHeight - 180,
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      inforList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        orderByColumn: "create_time",
        isAsc: "desc",
        title: null,
        type: null,
        content: null,
        createor: null,
        createTime: null,
        author: null,
        extend1: null,
        extend2: null,
        extend3: null,
        extend4: null,
        extend5: null,
        extend6: null,
        extend7: null,
        extend8: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        title: [
          { required: true, message: "标题不能为空", trigger: "blur" }
        ],
        type: [
          { required: true, message: "0：政策解读 1：党史百年 2：特色党建 3：三会一课 4：乡村振兴 5： 司机之家不能为空", trigger: "change" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listInfor(this.queryParams).then(response => {
        this.inforList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        title: null,
        type: null,
        content: null,
        createor: null,
        createTime: null,
        author: null,
        extend1: null,
        extend2: null,
        extend3: null,
        extend4: null,
        extend5: null,
        extend6: null,
        extend7: null,
        extend8: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    // 单击行选中数据
    handleRowClick(row, column, event) {
      this.$refs.list.toggleRowSelection(row);
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getInfor(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改【请填写功能名称】";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateInfor(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInfor(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除记录？').then(function() {
        return delInfor(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
  }
};
</script>
